//
//  HBHistoryCell.m
//  HeartBeat
//
//  Created by karong on 2023/8/28.
//

#import "HBHistoryCell.h"
#import "HBHistoryModel.h"
#import "UIView+WSDraw.h"
@interface HBHistoryCell ()
@property (weak, nonatomic) IBOutlet UIButton *vipBtn;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIButton *addBtn;
@property (weak, nonatomic) IBOutlet UILabel *authorLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *lastReadLabel;
@property (weak, nonatomic) IBOutlet UIButton *selectBtn;
@property (nonatomic, strong) HBHistoryModel * object;
@end

@implementation HBHistoryCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.vipBtn setupRoundedCornersWithCutCorners:(UIRectCornerTopLeft | UIRectCornerBottomRight) withRadii:CGSizeMake(8, 8)];
}

- (void)setDataWithObject:(HBHistoryModel *)object edit:(BOOL)edit {
    self.object = object;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:object.thumb] placeholderImage:HBPlaceholderImage];
    self.lastReadLabel.text = KEmptyStr(object.chapter_title);
    self.vipBtn.hidden = !object.is_vip;
    self.authorLabel.text = object.author;
    self.nameLabel.text = object.name;
    self.addBtn.hidden = edit || object.is_bookshelf;
    self.selectBtn.hidden = !edit;
    self.selectBtn.selected = object.isSelected;
    
}

- (IBAction)addAction:(id)sender {
    if ([self.delegate respondsToSelector:@selector(historyCell:addAction:)]) {
        [self.delegate historyCell:self addAction:self.object];
    }
}
@end
